// 公用 JavaScript Document

//通用选项卡
function tabclick(li,tabox,name){
	li.eq(0).addClass(name);
	tabox.eq(0).show();
	li.click(function(){
		$(this).addClass(name).siblings().removeClass(name);
		tabox.hide().eq(li.index(this)).show();
	});
}
function tabmouseover(li,tabox,name){
	li.eq(0).addClass(name);
	tabox.eq(0).show();
	li.mouseover(function(){
		$(this).addClass(name).siblings().removeClass(name);
		tabox.hide().eq(li.index(this)).show();
	});
}
function tabfade(li,tabox,name){
	li.eq(0).addClass(name);
	tabox.eq(0).fadeIn();
	li.click(function(){
		$(this).addClass(name).siblings().removeClass(name);
		tabox.fadeOut(1200).eq(li.index(this)).fadeIn(1200);
	});
}
//弹窗居中
function popcenter(popup){
    var width = popup.outerWidth(),
        height = popup.outerHeight();
    popup.css({
    "margin-left" : -width/2,
    "margin-top" : -height/2
    }).show();
}

//关闭渐隐效果
function onclikclose(idclass){
	$("."+idclass).animate({
		'height':'0px',
		'opacity':'0'
		});
}
//完善楼盘信息点击文字输入字符个数
function checkMessage(count,idclass,idnum)
{
	var strlen=0;
	$("."+idclass).keydown(function(){;
		strlen=$(this).val().length;
		if(strlen<count+1)
		{
			$("."+idnum).text(strlen);
		}
	});
}

//上一个、下一个切换一个li 左右切换
function scrollPic2(scrollArea,scrollUl,width,speed,num,prev,next){
    	var timeId, len = scrollUl.children("li").length;

	scrollArea.hover(function(){
         		clearInterval(timeId);
    	},function(){
        		if(scrollUl.children().length>num){
            			timeId=setInterval(function(){
            				if(scrollArea.is(":hidden")){
                					clearInterval(timeId);
                				}else{
	                				scrollPicNext();
                				}
            			},speed);
        		}
    	}).trigger("mouseleave");
    	
    	prev.click(function(){
    		scrollPicPrev();
    	});

    	next.click(function(){
    		scrollPicNext();
    	});

    	function scrollPicPrev(){
    		if(scrollUl.children().length>num){
	       		if(!scrollUl.is(":animated")){
	            			scrollUl.children().last().prependTo(scrollUl);
	            			scrollUl.stop(false,true).css("margin-left",-width+"px").animate({"margin-left":0},500);
	        		}
	    	}
    	}
    	function scrollPicNext(){
    		if(scrollUl.children().length>num){
	       		 if(!scrollUl.is(":animated")){
	            			scrollUl.stop(false,true).animate({"margin-left":-width+"px"},500,function(){
	                			scrollUl.css({"margin-left":"0"}).children().eq(0).appendTo(scrollUl);
	            			});
	        		}
	    	}
    	}
}

//上一个、下一个切换一个li 左右切换
function scrollRow(scrollArea,scrollUl,width,speed,num,prev,next){
  	var timeId, len = scrollUl.children("li").length;

	scrollArea.hover(function(){
       		clearInterval(timeId);
  	},function(){
      		if(scrollUl.children().length>num){
          			timeId=setInterval(function(){
          				if(scrollArea.is(":hidden")){
              					clearInterval(timeId);
              				}else{
	                				scrollPicNext();
              				}
          			},speed);
      		}
  	}).trigger("mouseleave");
  	
  	prev.click(function(){
  		scrollPicPrev();
  	});

  	next.click(function(){
  		scrollPicNext();
  	});

  	function scrollPicPrev(){
  		if(scrollUl.children().length>num){
	       		if(!scrollUl.is(":animated")){
	            			scrollUl.children().slice(len-num,len).prependTo(scrollUl);
	            			scrollUl.stop(false,true).css("margin-left",-width+"px").animate({"margin-left":0},800);
	        		}
	    	}
  	}
  	function scrollPicNext(){
  		if(scrollUl.children().length>num){
	       		 if(!scrollUl.is(":animated")){
	            			scrollUl.stop(false,true).animate({"margin-left":-width+"px"},800,function(){
	                			scrollUl.css({"margin-left":"0"}).children().slice(0,num).appendTo(scrollUl);
	            			});
	        		}
	    	}
  	}
}
//上一个、下一个切换一个li 上下切换
function scrollPicUD(scrollArea,scrollUl,height,speed,num,prev,next){
	var timeId,
       	        len = scrollUl.children("li").length;

       	scrollArea.hover(function(){
         		clearInterval(timeId);
    	},function(){
        		if(scrollUl.children().length>num){
            			timeId=setInterval(function(){
            				if(scrollArea.is(":hidden")){
                					clearInterval(timeId);
                				}else{
	                				scrollPicNext();
                				}
            			},speed);
        		}
    	}).trigger("mouseleave");
    	
    	prev.click(function(){
    		scrollPicPrev();
    	});

    	next.click(function(){
    		scrollPicNext();
    	});

    	function scrollPicPrev(){
    		if(scrollUl.children().length>num){
	       		if(!scrollUl.is(":animated")){
	            			scrollUl.children().last().prependTo(scrollUl);
	            			scrollUl.stop(false,true).css("margin-top",-height+"px").animate({"margin-top":0},1000);
	        		}
	    	}
    	}
    	function scrollPicNext(){
    		if(scrollUl.children().length>num){
	       		 if(!scrollUl.is(":animated")){
	            			scrollUl.stop(false,true).animate({"margin-top":-height+"px"},1000,function(){
	                			scrollUl.css({"margin-top":"0"}).children().eq(0).appendTo(scrollUl);
	            			});
	        		}
	    	}
    	}
}

//上一个、下一个切换一个li,按钮切换一组li
function scrollPic(scrollArea,scrollUl,width,speed,num,prev,next,menu){
    var timeId,
        add = 0,
        len = scrollUl.children("li").length;
    menu.eq(0).addClass("clicked");
    scrollArea.hover(function(){
        clearInterval(timeId);
    },function(){
        if(scrollUl.children().length>num){
            timeId=setInterval(function(){
            	if(scrollArea.is(":hidden")){
                	clearInterval(timeId);
                }else{
	                scrollUl.animate({"margin-left":-width+"px"},500,function(){
	                    scrollUl.css({"margin-left":"0"}).children().eq(0).appendTo(scrollUl);
	                });
	                add++;
	                if(add == len){
		                add = 0;
	                }
	                menu.eq(Math.floor(add/num)).addClass("clicked").siblings().removeClass("clicked");
                }
            },speed);
        }
    }).trigger("mouseleave");
    prev.click(function(){
    	if(scrollUl.children().length>num){
	        if(!scrollUl.is(":animated")){
	            scrollUl.children().last().prependTo(scrollUl);
	            scrollUl.stop(false,true).css("margin-left",-width+"px").animate({"margin-left":0},500);
	            add--;
	            if(add == -1){
	            	add = len-1;
	            }
	            menu.eq(Math.floor(add/num)).addClass("clicked").siblings().removeClass("clicked");
	        }
	    }
    });
    next.click(function(){
    	if(scrollUl.children().length>num){
	        if(!scrollUl.is(":animated")){
	            scrollUl.stop(false,true).animate({"margin-left":-width+"px"},500,function(){
	                scrollUl.css({"margin-left":"0"}).children().eq(0).appendTo(scrollUl);
	            });
	            add++;
	            if(add == len){
		                add = 0;
	                }
	            menu.eq(Math.floor(add/num)).addClass("clicked").siblings().removeClass("clicked");
	        }
	    }
    });
    menu.click(function(){
    	var lis = new Array();
    	var index = menu.index(this);
    	if(index > Math.floor(add/num)){
	        if(!scrollUl.is(":animated")){
	            scrollUl.stop(false,true).animate({"margin-left":-width*num*(index-Math.floor(add/num))+"px"},500,function(){
	                scrollUl.css({"margin-left":"0"});
	                for(var i = 0; i < num*(index-Math.floor(add/num)); i++){
	                	lis[i] = scrollUl.children("li").eq(0).appendTo(scrollUl);
	                }
	                menu.eq(index).addClass("clicked").siblings().removeClass("clicked");
	                add = index*num;
	            });

	        }
	    }else if(index < Math.floor(add/num)){
	    	if(!scrollUl.is(":animated")){
	            for(var i = 0; i < num*(Math.floor(add/num)-index); i++){
	                	scrollUl.children("li").last().prependTo(scrollUl);
	                }
	            scrollUl.stop(false,true).css("margin-left",-width*num+"px").animate({"margin-left":0},500,function(){
	            	menu.eq(index).addClass("clicked").siblings().removeClass("clicked");
	                add = index*num;
	            });
	        }
	    }
    });
}
//3张图片的大小转换效果
function fanImg(obj){
	var $box = obj,
		$lis = $box.children(),
		boxWidth = $box.width(),
		boxHeight = $box.height(),
		boxOffLeft = $box.offset().left,
		boxOffTop = $box.offset().top;
	$lis.mouseover(function(){
		if(!$lis.is(":animated")){
			if(!$(this).hasClass("bigPic")){
				var $bigPic = $(this).siblings(".bigPic"),
					bigOffLeft = $bigPic.offset().left - boxOffLeft,
					bigOffTop = $bigPic.offset().top - boxOffTop,
					bigWidth = $bigPic.width(),
					bigHeight = $bigPic.height(),
					bigOffRight = boxWidth - bigOffLeft - bigWidth,
					bigOffBottom = boxHeight - bigOffTop - bigHeight;
				$bigPic.width("100%");
				var offLeft = $(this).offset().left - boxOffLeft,
					offTop = $(this).offset().top - boxOffTop,
					width = $(this).width(),
					height = $(this).height(),
				 	offRight = boxWidth - offLeft - width,
				 	offBottom = boxHeight - offTop - height;

				var $another = $(this).siblings().not(".bigPic");
				$bigPic.removeClass("bigPic");
				var during = 400;
				if(offLeft >= offRight && offTop >= offBottom){
					$bigPic.css({
						"left" : "auto",
						"top" : bigOffTop,
						"right": bigOffRight
					}).animate({"width":width,"height":height},during,function(){

					});
					$another.css({
						"left" : bigOffLeft,
						"top" : offTop,
						"bottom" : "auto"
					}).animate({
						"top" : bigOffTop
					},during);
					$(this).css({
						"left" : "auto",
						"top" : "auto",
						"right" : offRight,
						"bottom" : offBottom
					}).animate({"width":bigWidth,"height":bigHeight},during,function(){
						$(this).addClass("bigPic").siblings().removeClass("bigPic");
					});
				}else if(offLeft >= offRight && offTop < offBottom){
					$bigPic.css({
						"left" : "auto",
						"right" : bigOffRight,
						"top" : "auto",
						"bottom" : bigOffBottom
					}).animate({"width":width,"height":height},during,function(){

					});
					$another.css({
						"top" : offTop,
						"left" : bigOffLeft,
						"bottom" : "auto"
					}).animate({
						"top" : boxHeight-height
					},during);
					$(this).css({
						"left" : "auto",
						"top" : offTop,
						"right" : offRight,
						"bottom" : "auto"
					}).animate({"width":bigWidth,"height":bigHeight},during,function(){
						$(this).addClass("bigPic").siblings().removeClass("bigPic");
					});
				}else if(offLeft < offRight && offTop >= offBottom){
					$bigPic.css({
						"left" : bigOffLeft,
						"top" : bigOffTop
					}).animate({"width":width,"height":height},during,function(){

					});
					$another.css({
						"left" : "auto",
						"top" : boxHeight-height,
						"right" : bigOffRight,
						"bottom" : "auto"
					}).animate({
						"top" : bigOffTop
					},during);
					$(this).css({
						"left" : offLeft,
						"bottom" : offBottom,
						"top" : "auto"
					}).animate({"width":bigWidth,"height":bigHeight},during,function(){
						$(this).addClass("bigPic").siblings().removeClass("bigPic");
					});
				}else if(offLeft < offRight && offTop < offBottom){
					$bigPic.css({
						"left" : bigOffLeft,
						"top" : "auto",
						"bottom" : bigOffBottom
					}).animate({"width":width,"height":height},during,function(){

					});
					$another.css({
						"left" : "auto",
						"top" : offTop,
						"right" : bigOffRight,
						"bottom" :"auto"
					}).animate({
						"top" : boxHeight-height
					},during);
					$(this).css({
						"left" : offLeft,
						"top" : offTop
					}).animate({"width":bigWidth,"height":bigHeight},during,function(){
						$(this).addClass("bigPic").siblings().removeClass("bigPic");
					});
				}
			}
		}
	});
}

$(function(){
	//主导航顶部搜索按钮
	$('.p_tpsearchbtn').click(function(e1) {
		e1.stopPropagation();
		var wth = $('.p_tpssbox').width();
		if (wth == 36) {
			$(this).siblings('div').show();
			$(this).parent('.p_tpssbox').css('background-color','#fff').animate({'width':'300px'},500,function(){
				$(this).css('overflow','visible');
			});
			$(this).addClass('clicked');
		};
	});
//	$('body').click(function(){
//		var box = $('.p_tpsearchbtn');
//		box.parent('.p_tpssbox').animate({'width':'36px'},300,function(){
//			box.parent('.p_tpssbox').css('background-color','transparent');
//			box.removeClass('clicked');
//			box.siblings('div').hide();
//		});
//	})
	//文本框提示
	$(".p_input").map(function(){
		var obj = $(this);
		var timeid = setInterval(function(){
			if(!obj.val()==""){
				obj.siblings(".intips").hide();
				clearInterval(timeid);
			}
		},10);
		$(".intips").click(function(){
			$(this).siblings(".p_input").focus();
		});

		$(this).bind({
			focus:function(){
				if (this.value == ""){
					$(this).siblings(".intips").hide();
					// $(this).attr("placeholder",$(this).siblings(".intips").text());
				}
			},
			blur:function(){
				if (this.value == ""){
					$(this).siblings(".intips").show();
					// $(this).removeAttr("placeholder");
				}
			}
		});
	})
    // 返回顶部
    var $goTop=$(".p_gotop");
	$goTop.hide();
	$(window).scroll(function(){
		if($(window).scrollTop()>500){
			$goTop.show();
		}else{
			$goTop.hide();
		}
	})
	$goTop.click(function(){
		var scrollTop=$(window).scrollTop();
		goTop(scrollTop);
	});
	function goTop(num){
		var timeid;
		timeid=setInterval(function(){
			if(num>0){
				num-=50;
				$(window).scrollTop(num);
			}else{
				clearInterval(timeid);
			}
		},10);
	}
	// 弹窗弹出隐藏
	$(".tc_btn").click(function(){
        $(".tc_maxbg").show();
        popcenter($(".tc_box"));
    });
    $(".tc_close").click(function(){
        $(".tc_maxbg").hide();
        $(".tc_box").hide();
    });

    //主导航显示隐藏效果
    var inMenu = $(".s_fixedmenu"),
		$nav = $('.p_topnavbox'),
		$close=$(".p_tpclose");
	var scrollTops = new Array();
	scrollTops[0] = $(window).scrollTop();
	if($(window).scrollTop()>30){
		if(!$close.is(":animated")){
			$close.animate({'top':'16px'},100);
		}
	}
	$(window).bind("scroll",function(e){
		//主导航展示效果
		if(!inMenu.length > 0){
			var newScrollTop = $(window).scrollTop(),
				len = scrollTops.length;
			if($(window).scrollTop() == 0){
				$nav.animate({'top':'0'},10);
			}
			scrollTops.push(newScrollTop);
		}
		if($(window).scrollTop()>30){
			if(!$close.is(":animated") && !$close.hasClass("downing")){
				$close.addClass("downing");
				$close.animate({'top':'16px'},10);
			}
		}else if(!$close.is(":animated") && $close.hasClass("downing")){
				$close.removeClass("downing");
			$close.animate({'top':'-36px'},10);
		}
	});
	$close.click(function() {
		$nav.stop(true,true).animate({'top':'-67px'},10);
	});
});
//导航搜索下拉框
$(function(){
	var ul = $('.p_insxuan'),
		li = ul.children('li');
	$('.p_insword').click(function(e){
		e.stopPropagation();
		var ssul = $(this).siblings('.p_insxuan');
		if (ssul.is(':hidden')) {
			ssul.slideDown();
		}else{
			ssul.slideUp();
		};
	});
	$("body").click(function(){
		ul.slideUp();
	});
	ul.hover(function() {
		li.click(function() {
			var index = $(this).index();
			$(this).parent('ul').siblings('.p_insword').text($(this).text());
			$(this).parent().parent().find('.p_insword').attr("data-id", $(this).data("id"));
			$(this).parent('ul').siblings('ul').children('li').hide().eq(index).show();
			$(this).parent('ul').slideUp();
			// e.stopPropagation();
		});
	}, function() {
		$(this).slideUp();
	});
	$('.p_tpssbox').click(function(e) {
		e.stopPropagation();
	});
	$(".p_insstext").map(function(){
		var obj = $(this);
		var timeid = setInterval(function(){
			if(!obj.val()==""){
				obj.parent().siblings().find(".p_ssrtul").hide();
				clearInterval(timeid);
			}
		},10);
		$(this).bind({
			focus:function(){
				if (this.value == ""){
					$(this).parent().siblings().find(".p_ssrtul").hide();
				}
			},
			blur:function(){
				if (this.value == ""){
					$(this).parent().siblings().find(".p_ssrtul").show();
				}
			}
		});
	})
})
// 浮动选项卡导航条 、 nav隐藏显示
$(function(){
	var inMenu = $(".s_fixedmenu"),
		$main = $(".s_homemain"),
		$nav = $(".p_topnavbox"),
		height = $nav.height();
	if(inMenu.length > 0){
		var offTop = $main.offset().top;
		$(window).scroll(function(){
			var scrollTop = $(window).scrollTop();
			if(scrollTop > offTop + 85){
				animateUp($nav,10);
				if(scrollTop + height > offTop){
					inMenu.addClass("onfixed");
				}
			}else{
				if(scrollTop == 0){
					animateDown($nav,10);
				}
				inMenu.removeClass("onfixed");
			}
			inMenu.children().not("clicked").click(function(){
				if(inMenu.hasClass("onfixed")){
					$("html,body").stop().animate({"scrollTop":offTop},10);
				}
			});
		});
	}
});

function animateUp(obj,time){
	if(!obj.is(":animated")){
		obj.stop().animate({"top":-obj.height()},time);
	}
}
function animateDown(obj,time){
	if(!obj.is(":animated")){
		obj.stop().animate({"top":0},time);
	}
}
//模拟select
$(function(){
	selectMN($(".m_select_span"));
	function selectMN($select){
		$select.each(function(index, value){
			$select.eq(index).click(function(event){
				event.stopPropagation();
				selectUp($select);
				if($(this).children(".m_select_chList").is(":hidden")){
					selectDown($(this));
				} else {
					selectUp($(this));
				}
				var selectLis = $(this).children(".m_select_chList").find("li");
				selectLis.each(function(index){
					selectLis.eq(index).click(function(){
						$(this).parent().siblings(".fl").text($(this).text());
						$(this).find(".m_bottom").show();
						$(this).find(".m_top").hide();
					});
				});
			});
		});
		$("body").click(function(){
			selectUp($select);
		});

		function selectUp($obj){
			$obj.children(".m_select_chList").stop().slideUp(200);
			$obj.find(".m_bottom").show();
			$obj.find(".m_top").hide();
		}
		function selectDown($obj){
			$obj.children(".m_select_chList").stop().slideDown(200);
			$obj.find(".m_top").show();
			$obj.find(".m_bottom").hide();
		}
	}
});
//登陆注册弹窗
function windivmax(idclassbox,id_class,id_close)
{
	var $w=$(window).width(),
	 $h=$(window).height(),
	  $H=$(document).height(),
	  $mw=$("."+id_class).width(),
	 $mh=$("."+id_class).height(),
	 strtop=($h-$mh)/2,
	 strleft=($w-$mw)/2;
	$("."+idclassbox).css("height",$H+'px').show();
	 $("."+id_class).css("left",strleft+'px').css("top",strtop+'px').show();
	 $("."+id_close).click(function(){
		$("."+id_class).hide();
		$("."+idclassbox).hide();
		var _url_ = window.location.href;
		if(_url_.indexOf("/index.do") > 0&&_url_.indexOf("share_user")<0){
			if(hasParameter("nologin")){
				_url_ = replaceParamVal(_url_, "nologin", 0);
			}
			location.href=_url_;
		}
	});
	 $(window).resize(function(){
	 	var $w=$(window).width(),
			 $h=$(window).height(),
			  $H=$(document).height(),
			  $mw=$("."+id_class).width(),
			 $mh=$("."+id_class).height(),
			 strtop=($h-$mh)/2,
			 strleft=($w-$mw)/2;
			$("."+idclassbox).css("height",$H+'px');
			 $("."+id_class).css("left",strleft+'px').css("top",strtop+'px');
	 });
}
//登录弹窗调用
$(function(){
	$(".login").click(function(){
		$(".ly_regmain").hide();
		windivmax("ly_loginbox","ly_loginmain01","ly_loginclose");
	});
});
//注册弹窗调用
$(function(){
	$(".reg").click(function(){
		$(".ly_loginmain01").hide();
		windivmax("ly_loginbox","ly_regmain","ly_loginclose");
	});
});
$(function(){
	//$(".s_registerbtn").click(function(){
	//	$(".ly_regmain").hide();
	//	windivmax("ly_loginbox","s_registerok","ly_loginclose")
	//});
});
//找回密码弹窗调用

$(function(){
	$(".idcard").click(function(){
		$(".ly_loginmain").hide();
		windivmax("ly_loginbox","ly_emailWrap","ly_loginclose")
	});
});

//找回密码步骤弹窗调用
$(function(){
	$(".ly_idcradway").click(function(){
		$(".ly_idcradjdtper").width(168);
		$(".ly_emailWrap,.ly_loginbox").hide();
		var strId=$(".ly_idcradjdtli>li"),
		 strobj=$(".ly_passwrodjdt>li");
		 strobj.hide();
		strId.eq(0).addClass("active");
		strobj.eq(0).show();
		
		windivmax("ly_loginbox","ly_idcradWrap","ly_loginclose");
		settime(1,"ly_idcradjdtper");
		/*$(".ly_passwrodjdt").find(".ly_idcradnext").each(function(index){
			$(this).click(function(){
				strId.eq(index+1).addClass("active");
				strobj.hide().eq(index+1).show();
				settime(index+2,"ly_idcradjdtper");
			})

		})*/
	});
});

/*=================banner图 自定义宽度 淡入淡出===============*/
function banner($liList, $cur, $curBox,$wrapper){
	var curIndex = 0;

	$liList.each(function(index){
		$liList.eq(index).css({"background":"url("+$liList.eq(index).attr("_src")+") center","background-size":"cover"});
	});
	$liList.eq(curIndex).css({"opacity":"1","z-index":"99"});
	var curList = $cur.find("li");
	curList.eq(curIndex).addClass("m_cur_on");

	var curWidth = curList.eq(curIndex).width();
	        ml = parseInt(curList.eq(0).css("margin-left"));
	$curBox.css("width",(curWidth+ml)*curList.length+"px").css("margin-left",-curWidth*curList.length/2+"px");

	curList.mouseover(function(){
		var index = $(this).index();
		if(index != curIndex){
			curList.removeClass("m_cur_on").eq(index).addClass("m_cur_on");
			$liList.eq(curIndex).stop().animate({
				"opacity":0,"z-index":"10"
			},1500);
			$liList.eq(index).stop().animate({
				"opacity":1,"z-index":"99"
			},1500);
			curIndex = index;
		}
	});
	function slidePrev(curIndex){
		var index = curIndex-1;
		if(curIndex == 0){
			index = $liList.length-1;
		}
		bannerSlide(curIndex, index);
		return index;
	}
	function slideNext(curIndex){
		var index = curIndex+1;
		if(curIndex == $liList.length-1){
			index = 0;
		}
		bannerSlide(curIndex, index);
		return index;
	}
	function bannerSlide(curIndex, index){
		curList.removeClass("m_cur_on").eq(index).addClass("m_cur_on");
		$liList.eq(curIndex).stop().animate({
			"opacity":0,"z-index":"10"
		},1500);
		$liList.eq(index).stop().animate({
			"opacity":1,"z-index":"99"
		},1500);
	}

	/*----------自动切换------------*/
	var timeLock;
	function start(){
		timeLock = setInterval(function(){
       			 curIndex = slideNext(curIndex);
	    	},3000)
	}
	start();
	$wrapper.hover(
		function(){
			clearInterval(timeLock);
		},
		function(){
			start();
		}
	);
	return curList.length;
}
/*=================banner图 自定义宽度 滑动===============*/
/* $liList----->li
     $cur------>cur li
     $curBox ----->cur
     $wrapper -----> div盒子
     speed ----->切换速度
*/
function bannerHD($liList, $cur, $curBox,$wrapper,speed,$prev,$next){
	var bodyWidth = $wrapper.outerWidth(),//banner的显示宽度
	       curIndex = 0;
	
	$liList.each(function(index){
		$liList.eq(index).css("left",index*bodyWidth+"px");
	});

	if($cur != null && $curBox != null){
		var curList = $cur.find("li"),
	      	        ml = parseInt(curList.eq(0).css("margin-left"));

		/*---------初始化按钮------------*/
		curList.eq(curIndex).addClass("m_cur_on");

		var curWidth = curList.eq(curIndex).width()
		$curBox.css("width",(curWidth+ml)*curList.length+"px").css("margin-left",-curWidth*curList.length/2+"px");

		/*-------------------按钮点击------------*/
		curList.click(function(){
			var index = $(this).index();
			if(index != curIndex){
				if(index < curIndex){
					bannerSlide(index,curIndex,-bodyWidth);
				} else {
					bannerSlide(index,curIndex,bodyWidth);
				}
				curIndex = index;
			}	
		});
	}
	/*-------------prev点击-------------*/
	if ($prev != null) {
		$prev.click(function(){
			if(! $liList.is(":animated")){
				curIndex = slidePrev(curIndex);
			}
		});
	};
	/*--------------next点击--------------*/
	if ($next != null) {
		$next.click(function(){
			if(! $liList.is(":animated")){
				curIndex = slideNext(curIndex);
			}
		});
	};
	/*--------------滑动效果---------------*/
	function slidePrev(curIndex){
		if(curIndex !=0){
			var index = curIndex-1;
		} else {
			index = $liList.length-1;
		}
		
		bannerSlide(index,curIndex,-bodyWidth);

		curIndex = index;
		return index;
	}

	function slideNext(curIndex){
		if(curIndex!=$liList.length-1){
			var index = curIndex+1;
		} else {
			index = 0;
		}
		
		bannerSlide(index,curIndex,bodyWidth);

		curIndex = index;
		return index;
	}
	function bannerSlide(index,curIndex,width){
		if($liList.length > 1){
			if($cur != null && $curBox != null){
				curList.removeClass("m_cur_on").eq(index).addClass("m_cur_on");
			}
			$liList.eq(index).css("left",width+"px");
	
			$liList.eq(curIndex).stop().animate({
				"left": -width+"px"
			},speed);
	
			$liList.eq(index).stop().animate({
				"left": 0
			},speed);
		}
	}

	/*----------自动向前滚动------------*/
	var timeLock;
	function start(){
		timeLock = setInterval(function(){
       			curIndex = slideNext(curIndex);
	    	},4000);
	}
	start();
	$wrapper.hover(
		function(){
			clearInterval(timeLock);
		},
		function(){
			start();
		}
	);
}

//户型主页（户型秀家）
$(function(){
	var love = $(".m_show_love");
	love.each(function(index,value){
		love.eq(index).click(function(){
			var num = parseInt($(this).find(".m_show_num").text());
			if($(this).hasClass("m_show_loveOn")){
				$(this).removeClass("m_show_loveOn");
				$(this).find(".m_show_num").text(num-1);
			} else {
				$(this).addClass("m_show_loveOn");
				$(this).find(".m_show_num").text(num+1);
			}
		});
	});
});

/*yyy-帮助中心-左侧导航*/
$(function(){
	$(".y_bznavul").find(".click").children(".y_bznav2").show().siblings().find(".fr").text("-");
	$(".y_bznavul>li>a").click(function(){
		var ul=$(this).parent().children("ul");
			uls=$(this).parent().siblings().children("ul");
		if(ul.is(":hidden")){
			ul.slideDown();
			uls.slideUp();
			$(this).parent().addClass("click").find(".fr").text("-");
			$(this).parent().siblings().removeClass("click").find(".fr").text("+");
		}else{
			ul.slideUp();
			$(this).parent().find(".fr").text("+");
		}
	})
})
/*帮助中心-广告图*/
$(function(){
	scrollDiv($(".y_bzimg"),$(".y_bzlist li"),$(".y_bzimgul li"),"click");
	scrollDiv($(".y_dpzndiv"),$(".y_dpznlist li"),$(".y_dpzndivul li"),"click");
	scrollDiv($(".y_dpznxqdiv"),$(".y_dpznxqlist li"),$(".y_dpznxqdivul>li"),"click");
})
//******************ye--广告图--小banner图**********************
function scrollDiv(parent,control,scrolldiv,className){
		var i=0,
			timeId,
			len=scrolldiv.length;
		control.click(function(){
			$(this).addClass(className).siblings().removeClass(className);
			var index=$(this).index();
			scrolldiv.fadeOut(200).eq(index).fadeIn(200);
			i=index;
		});
		parent.hover(function(){
			clearInterval(timeId);	
		},function(){
			timeId=setInterval(function(){
				if(i<len-1){
					control.eq(i+1).trigger("click");
				}else{
					control.eq(0).trigger("click");	
				}
			},5000);
		}).trigger("mouseleave");
}

$(function(){
	var $a = $(".y_yqlj").find("a");
	for(var i = 0; i < $a.length; i++){
		$a.eq(8*i-1).css("margin-right",0).next().css("width",0);
	}
})

/*===============瀑布流==============*/
function waterfall($one, mt){
	oneWidth = $one.eq(0).width(); // 一个块框pin的宽
	var ml = parseInt($one.css("margin-left"));
	num = Math.floor($(".m_wdlp_waterBox").width()/(oneWidth+ml)); //每行中能容纳的pin个数
	var oneHArr=[]; //用于存储 每列中的所有块框相加的高度。
	var maxH = 0; //存储最高的列

	$one.each(function(index, value){
		var oneH = $one.eq(index).height();
		if(index<num){
			oneHArr[index] = oneH;
		} else {
			var minH = Math.min.apply( null, oneHArr ); //数组oneHArr中的最小值minH
			var minHIndex = $.inArray( minH, oneHArr );
			$(value).css({
                				'position': 'absolute',
                				'top': minH + mt,
                				'left': $one.eq( minHIndex ).position().left
            			});
			//数组 最小高元素的高 + 添加上的aPin[i]块框高
            			oneHArr[ minHIndex ] += $one.eq(index).height() + mt;//更新添加了块框后的列高
		}
		maxH = Math.max.apply(null, oneHArr)
	});
	$(".m_wdlp_waterBox").css("height",maxH+20);
}

//鼠标移入小图显示大图
$(function(){
	var timeid;
	$(".y_lpuls>li").map(function(){
		var that=$(this);
		var lis=$(this).find(".y_lpul2").children("li");
		lis.mouseover(function(){
			var the = $(this);
			clearTimeout(timeid);
			timeid = setTimeout(function(){
				var img1=that.find(".y_lpbigimg").children("img").attr("src");
				var img2=the.children("img").attr("src");
				the.children("img").attr("src",img1);
				the.parent().siblings(".y_lpbigimg").children("img").attr("src",img2);
			},200);
		});
	});
});

//瀑布流
$(function(){
	$(".m_hxxj_reviewList").each(function(index){
		$(this).find("li").addClass("clr").last().css("border","none");
	});
});

//20151231 修改
function scrollpic(scrollArea,scrollUl,speed,num,line){
	var timeId,
		height=scrollUl.children("li").outerHeight(true);
	scrollArea.hover(function(){
		clearInterval(timeId);
	},function(){
		if(scrollUl.children("li").length>=num*line){
			timeId=setInterval(function(){
				scrollUl.animate({"margin-top":-height+"px"},777,function(){
					scrollUl.css("margin-top","0");
					for (var s = 0; s < num; s++) {
						scrollUl.find("li").eq(0).appendTo(scrollUl);
					};
				});
			},speed);
		}
	}).trigger("mouseleave");
}

$(function(){
	scrollpic($('.p_1230scrolbox'),$('.p_in_hothumer'),3500,3, 2);
	scrollpic($('.p_1231scrolbox'),$('.m_jjsc_sdList'),3500,2, 2);
})

//图片居中
//$(function(){
//	onload = function(){
//		var img = $('.p_xj_scroul>li img'),
//			width = img.width(),
//			height = img.height(),
//			w = img.parent().width(),
//			h = img.parent().height();
//		if(w/h > width/height){
//			img.css({
//				'width': 'auto',
//				'height': '100%'
//			});
//		}else{
//			img.css({
//				'width': '100%',
//				'height': 'auto'
//			});
//		}
//		
//	}
//});










